package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/book")
public class BookController {
    //获取图书列表
    @RequestMapping("/getlist")
    public List<Books> getlist(){
        List<Books> books=new ArrayList<>();
        //处理页面呈现
        for (Books book:books){
            if(book.getStatus()=="1"){
                book.setStatus("可借阅");
            }else{
                book.setStatus("不可借阅");
            }
        }
        return books;
    }
    @RequestMapping("/mockData")
    public List<Books> mockData(){
        List<Books> books=new ArrayList<>();
        for (int i=0;i<10;i++){
            Books newbook=new Books();
            newbook.setId(i);
            newbook.setAuthor("作者"+i);
            newbook.setBookName("书名"+i);
            newbook.setCout(new Random().nextInt(200));
            newbook.setPrice(new BigDecimal(new Random().nextInt(100)));
            newbook.setStatus(String.valueOf(i%2+1));
            books.add(newbook);
        }
        return books;
    }
}
